#include "comm.h"
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<unistd.h>

int main()
{
	key_t k = ftok(PATH_NAME,PROJ_ID);
	if(k < 0)
	{
		perror("ftok");
		return 1;
	}
	printf("key: %x\n",k);

	int shmid = shmget(k,SIZE,IPC_CREAT|IPC_EXCL|0644);
	if(shmid < 0)
	{
		perror("shmget");
		return 2;
	}
	printf("shmid: %d\n",shmid);

	char* start = (char*)shmat(shmid,NULL,0);
	printf("server already attach on shared memory!\n");

	while(1)
	{
		printf("%s\n",start);
		sleep(1);
	}
	shmdt(start);
	shmctl(shmid,IPC_RMID,NULL);
	printf("delete shm!\n");
	return 0;
}
